package es.udc.pfc.davidparedes.web.pages.user;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import es.udc.pfc.davidparedes.model.mission.Mission;
import es.udc.pfc.davidparedes.model.shift.Shift;
import es.udc.pfc.davidparedes.model.store.Store;
import es.udc.pfc.davidparedes.model.storeservice.StoreService;
import es.udc.pfc.davidparedes.model.storeservice.UniverseCurrentActivityDTO;
import es.udc.pfc.davidparedes.model.task.Task;
import es.udc.pfc.davidparedes.model.userprofile.UserProfile;
import es.udc.pfc.davidparedes.model.userservice.UserService;
import es.udc.pfc.davidparedes.model.util.GlobalNames;
import es.udc.pfc.davidparedes.model.util.InstanceNotFoundException;
import es.udc.pfc.davidparedes.web.services.AuthenticationPolicy;
import es.udc.pfc.davidparedes.web.services.AuthenticationPolicyType;
import es.udc.pfc.davidparedes.web.util.UserSession;

@AuthenticationPolicy(AuthenticationPolicyType.RECEPTIONIST_OR_ABOVE)
public class CurrentWorkers {
	
	@Property
	private UserProfile userProfile;
	
	@Property
	private Store store;
	
	@Property
	private ArrayList<UniverseCurrentActivityDTO> dtoList;
	
	@Property
	private UniverseCurrentActivityDTO universeInfo;
	
	@Property
	private Task task;
	
	@Property
	private Shift shift;
	
	@Property
	private Mission mission;
	
	@Property
	private List<Mission> missions;
    
    @SessionState(create=false)
    private UserSession userSession;
    
    @Inject
    private UserService userService;
    
    @Inject
    private StoreService storeService;
    
    void onActivate() {
    	try {
			userProfile = userService.findUserProfile(userSession.getUserProfileId());
			store = userProfile.getStore();
			dtoList = (ArrayList<UniverseCurrentActivityDTO>) storeService.getCurrentActivity(store.getStoreId());
			missions = storeService.getCurrentMissions(store.getStoreId());
    	} catch (InstanceNotFoundException e) {
		}
    }
    
    public boolean isMorningPermanent(Shift shift) {
    	if (shift.getPermanent()==GlobalNames.SHIFT_PERMANENT_MORNING) {
    		return true;
    	}
    	return false;
    }
    
    public boolean isEveningPermanent(Shift shift) {
    	if (shift.getPermanent()==GlobalNames.SHIFT_PERMANENT_EVENING) {
    		return true;
    	}
    	return false;
    }
    
    public boolean isOn(Task task) {
    	if ((task.getType()==GlobalNames.TASK_VACATION)
    			|| (task.getType()==GlobalNames.TASK_LOW)
    				|| (task.getType()==GlobalNames.TASK_ABSENTEEISM)){
    		return false;
    	}
    	return true;
    }

}
